package com.pcbly.web.components.utils.jfreechart;

import java.awt.Font;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart; 
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.util.Rotation;

public class PieChart3D  extends AbstractChartFont {
	/**
	 * 构造数据集合
	 * 
	 * @return
	 */
	private  PieDataset getDataSet() {
		
		DefaultPieDataset pieDataset = new DefaultPieDataset();
		
		pieDataset.setValue("棉花", 1.9D);
		pieDataset.setValue("小麦", 1.2D);
		pieDataset.setValue("水稻", 3.9D);
		pieDataset.setValue("大豆", 2.4D);
		pieDataset.setValue("玉米", 3.4D);
		pieDataset.setValue("花生", 5.4D);
		return pieDataset;
	}
	/**
	 * 根据数据集合创建JFreeChart对象
	 * 
	 * @param pieDataset
	 * @return
	 */
	private  JFreeChart createJFreeChart(PieDataset pieDataset) {
		StandardChartTheme standardChartTheme = new StandardChartTheme("name");
		standardChartTheme.setLargeFont(new Font("宋体",Font.BOLD, 10));//可以改变轴向的字体
		standardChartTheme.setRegularFont(new Font("宋体",Font.BOLD, 15));//可以改变图例的字体
		standardChartTheme.setExtraLargeFont(new Font("宋体",Font.BOLD, 24));//可以改变图标的标题字体
		ChartFactory.setChartTheme(standardChartTheme);
		JFreeChart chart = ChartFactory.createPieChart3D("某地区主要农作物种植比例饼状图",
				pieDataset, true, true, false);  
		
		PiePlot3D pieplot3d = (PiePlot3D)chart.getPlot();
		pieplot3d.setStartAngle(270D);
		pieplot3d.setSimpleLabels(true);
		pieplot3d.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}({2})"));
        pieplot3d.setDirection(Rotation.ANTICLOCKWISE);
        pieplot3d.setForegroundAlpha(0.6F);
        
		return chart;
	}
	
	public JFreeChart index(){
		PieDataset dataset=getDataSet();
		return createJFreeChart(dataset); 
	}
}
